Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export module #1

Draft
wants to merge 4 commits into
base: inference
Choose a base branch
from
Draft

Add export module #1

wants to merge 4 commits into from

Conversation

ckanesan
Copy link
Owner

@ckanesan ckanesan commented Jan 6, 2022

Adds a module that exports the model to the ONNX framework and executes a test run.
Some minor modifications are made to the model to make it exportable but should not affect the outputs.

@@ -120,14 +120,18 @@ def forward(self, images, annotations = None):
#jloc_pred_nms = non_maximum_suppression(jloc_pred[0])
#topK = torch.clamp((jloc_pred_nms > 0.008).count_nonzero(), max=300)

juncs_pred, _ = get_junctions(non_maximum_suppression(jloc_pred[0]),joff_pred[0], topk=300, th=0.008)
nms_jloc_pred = non_maximum_suppression(jloc_pred)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part where I pass the 4 dimensional tensor, and then take out the batch dim after max_pool2d

Comment on lines +130 to +128
# idx_junc_to_end_min = torch.min(idx_junc_to_end1,idx_junc_to_end2)
# idx_junc_to_end_max = torch.max(idx_junc_to_end1,idx_junc_to_end2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch.min and torch.max signatures are (tensor, dim, keep_dims, ..)
They are used here are torch.min/max(tensor1, tensor2) to do element-wise minimum/maximum operations.
This does not work for onnx, as it sees min and max, and expects the second argument to be an integer, and not a tensor.

The fix is to stack the two tensors together, then take the min/max along the stacked dimension.

wireframe = WireframeGraph(juncs_final,juncs_score,edge_indices,score_final,output.size(3),output.size(2))
wireframe.rescale(annotations[0]['width'],annotations[0]['height'])
else:
return juncs_final,juncs_score,edge_indices,score_final,output.size(3),output.size(2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output.size(3) and output.size(2) are not tensors anymore, they probably won't have meaningful data once exported

@ckanesan ckanesan changed the title WIP Add export module Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants